package com.iknow.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask.Status;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.iknow.IKnow;
import com.iknow.IKnowApiV4;
import com.iknow.User;
import com.iknow.app.IKnowSystemConfig;
import com.iknow.db.IKnowDataBase;
import com.iknow.file.CacheSystem;
import com.iknow.http.HttpException;
import com.iknow.image.ImageManager;
import com.iknow.image.ProfileImageCacheManager;
import com.iknow.task.GenericTask;
import com.iknow.task.TaskAdapter;
import com.iknow.task.TaskListener;
import com.iknow.task.TaskParams;
import com.iknow.task.TaskResult;
import com.iknow.util.Loger;
import com.iknow.util.StringUtil;
import com.iknow.xmpp.service.aidl.IKnowUser;
import com.iknow.xmpp.service.aidl.IXmppConnection;
import com.iknow.xmpp.service.aidl.IXmppFacade;
import com.iknow.xmpp.service.aidl.IXmppFacade.Stub;
import java.io.File;

public class UserInfoActivity extends Activity
{
  public static final int REQUEST_CHANGE_ACCOUNT = 4;
  public static final int REQUEST_CHANGE_AVTAR = 1;
  public static final int REQUEST_CHANGE_FLAG = 6;
  public static final int REQUEST_CHANGE_NICK = 3;
  public static final int REQUEST_CHANGE_SEX = 2;
  public static final int REQUEST_CHANGE_SIGNATRUE = 5;
  private static final int REQUEST_IMAGE_CAPTURE = 7;
  private static final int REQUEST_PHOTO_LIBRARY = 8;
  private static final Intent SERVICE_INTENT = new Intent();
  private View.OnClickListener AccountClickListener;
  private View.OnClickListener BackBtnClickListener;
  private View.OnClickListener FlagClickListener;
  private View.OnClickListener GenderClickListener;
  private View.OnClickListener HeadImageSelectClickListener;
  private View.OnClickListener NickClickListener;
  private View.OnClickListener SignatureClickListener;
  private final String TAG = "UserInfoActivity";
  private ProgressDialog dialog;
  private View.OnClickListener logOutClickListener;
  private RelativeLayout mAccountLayout;
  private TextView mAccountTextView;
  private boolean mBinded;
  private Button mButtonAction;
  private Button mButtonLogOut;
  private String mCurrentSelectPhoto;
  private RelativeLayout mFlagLayout;
  private TextView mFlagTextView;
  private RelativeLayout mGenderLayout;
  private TextView mGenderText;
  private RelativeLayout mHeadLayout;
  private ImageView mHeadView;
  private File mImageFile;
  private Uri mImageUri;
  private RelativeLayout mNickLayout;
  private EditText mPasswordEditText;
  private Bitmap mSelectBimap;
  private Spinner mSexSpinner;
  private RelativeLayout mSignatrueLayout;
  private TextView mSignatrueTextView;
  private ServiceConnection mSvrConn;
  private UserInfoTask mTask;
  private TaskListener mTaskListener;
  private User mUser;
  private TextView mUsernameTextView;
  private IXmppFacade mXmppFacade;

  static
  {
    SERVICE_INTENT.setComponent(new ComponentName("com.iknow", "com.iknow.xmpp.service.IKnowXmppService"));
  }

  public UserInfoActivity()
  {
    this.mSvrConn = new XmppServiceConnection(this, null);
    this.mHeadLayout = null;
    this.mNickLayout = null;
    this.mGenderLayout = null;
    this.mAccountLayout = null;
    this.mSignatrueLayout = null;
    this.mFlagLayout = null;
    this.mUsernameTextView = null;
    this.mPasswordEditText = null;
    this.mCurrentSelectPhoto = null;
    this.HeadImageSelectClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        UserInfoActivity.access$0(this.this$0);
      }
    };
    this.NickClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        Intent localIntent = new Intent(this.this$0, InforEditActivity.class);
        localIntent.putExtra("code", 3);
        localIntent.putExtra("data", UserInfoActivity.access$1(this.this$0).getNick());
        this.this$0.startActivityForResult(localIntent, 3);
      }
    };
    this.GenderClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        Intent localIntent = new Intent(this.this$0, InforEditActivity.class);
        localIntent.putExtra("code", 2);
        localIntent.putExtra("data", UserInfoActivity.access$1(this.this$0).getGender());
        this.this$0.startActivityForResult(localIntent, 2);
      }
    };
    this.AccountClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        Intent localIntent = new Intent(this.this$0, InforEditActivity.class);
        localIntent.putExtra("code", 4);
        localIntent.putExtra("data", UserInfoActivity.access$1(this.this$0).getPassword());
        this.this$0.startActivityForResult(localIntent, 4);
      }
    };
    this.SignatureClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        Intent localIntent = new Intent(this.this$0, InforEditActivity.class);
        localIntent.putExtra("code", 5);
        localIntent.putExtra("data", UserInfoActivity.access$1(this.this$0).getSignature());
        this.this$0.startActivityForResult(localIntent, 5);
      }
    };
    this.FlagClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        Intent localIntent = new Intent(this.this$0, IndentityFlagActivity.class);
        localIntent.putExtra("flag", UserInfoActivity.access$1(this.this$0).getIntroduction());
        this.this$0.startActivityForResult(localIntent, 6);
      }
    };
    this.BackBtnClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        this.this$0.finish();
      }
    };
    this.logOutClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        IKnow.mApi.logout();
        if (UserInfoActivity.access$2(this.this$0) != null);
        try
        {
          UserInfoActivity.access$2(this.this$0).disconnect();
          this.this$0.finish();
          Toast.makeText(this.this$0, "已注销", 0).show();
          return;
        }
        catch (RemoteException localRemoteException)
        {
          localRemoteException.printStackTrace();
        }
      }
    };
    this.mTaskListener = new TaskAdapter(this)
    {
      public String getName()
      {
        return "UserInfo";
      }

      public void onCancelled()
      {
      }

      public void onPostExecute(, TaskResult paramTaskResult)
      {
        if (paramGenericTask instanceof UserInfoActivity.UserInfoTask)
        {
          if (paramTaskResult != TaskResult.OK)
            break label22;
          UserInfoActivity.access$4(this.this$0);
        }
        while (true)
        {
          return;
          label22: UserInfoActivity.access$5(this.this$0, ((UserInfoActivity.UserInfoTask)paramGenericTask).getMsg());
        }
      }

      public void onPreExecute()
      {
        UserInfoActivity.access$3(this.this$0, "请稍等");
      }

      public void onProgressUpdate(, Object paramObject)
      {
      }
    };
  }

  private void initView()
  {
    this.mHeadLayout = ((RelativeLayout)findViewById(2131296442));
    this.mHeadLayout.setOnClickListener(this.HeadImageSelectClickListener);
    this.mAccountTextView = ((TextView)findViewById(2131296415));
    this.mAccountTextView.setText(this.mUser.getEmail());
    this.mGenderText = ((TextView)findViewById(2131296328));
    this.mUsernameTextView = ((TextView)findViewById(2131296449));
    this.mUsernameTextView.setText(this.mUser.getNick());
    this.mButtonAction = ((Button)findViewById(2131296342));
    this.mButtonAction.setOnClickListener(this.BackBtnClickListener);
    findViewById(2131296344).setVisibility(8);
    this.mButtonLogOut = ((Button)findViewById(2131296447));
    this.mButtonLogOut.setOnClickListener(this.logOutClickListener);
    String str = this.mUser.getGender();
    if (str.equalsIgnoreCase("1"))
      this.mGenderText.setText("男");
    while (true)
    {
      while (true)
      {
        this.mHeadView = ((ImageView)findViewById(2131296338));
        if (!(StringUtil.isEmpty(this.mUser.getImageId())))
          IKnow.mProfileImageCacheManager.displayProfileBimap(this.mHeadView, this.mUser.getImageId());
        this.mHeadView.setOnClickListener(this.HeadImageSelectClickListener);
        this.mSignatrueTextView = ((TextView)findViewById(2131296330));
        this.mSignatrueTextView.setText(this.mUser.getSignature());
        this.mFlagTextView = ((TextView)findViewById(2131296458));
        this.mFlagTextView.setText(this.mUser.getIntroduction());
        this.mNickLayout = ((RelativeLayout)findViewById(2131296448));
        this.mNickLayout.setOnClickListener(this.NickClickListener);
        this.mGenderLayout = ((RelativeLayout)findViewById(2131296450));
        this.mGenderLayout.setOnClickListener(this.GenderClickListener);
        this.mAccountLayout = ((RelativeLayout)findViewById(2131296452));
        this.mAccountLayout.setOnClickListener(this.AccountClickListener);
        this.mSignatrueLayout = ((RelativeLayout)findViewById(2131296454));
        this.mSignatrueLayout.setOnClickListener(this.SignatureClickListener);
        this.mFlagLayout = ((RelativeLayout)findViewById(2131296456));
        this.mFlagLayout.setOnClickListener(this.FlagClickListener);
        return;
        if (!(str.equalsIgnoreCase("2")))
          break;
        this.mGenderText.setText("保密");
      }
      this.mGenderText.setText("女");
    }
  }

  private void onImageSelected(Uri paramUri)
  {
    if (paramUri == null);
    do
      return;
    while ((paramUri.getScheme() == null) && (paramUri.getPath() == null));
    if ((paramUri.getScheme() != null) && (paramUri.getScheme().equals("content")))
      this.mImageUri = paramUri;
    while (true)
    {
      while (true)
      {
        ImageManager localImageManager;
        String str;
        do
        {
          localImageManager = IKnow.mProfileImageCacheManager.getImageManager();
          str = IKnow.mCacheSystem.getThumbmailFileName(paramUri.getPath());
          this.mSelectBimap = localImageManager.createThumbnailBitmap(this.mImageUri, 200);
        }
        while (this.mSelectBimap == null);
        this.mCurrentSelectPhoto = localImageManager.bitmapToFile(this.mSelectBimap, str).getAbsolutePath();
        this.mHeadView.setImageBitmap(localImageManager.createThumbnailBitmap(this.mImageUri, 200));
        this.mHeadView.setVisibility(0);
        TaskParams localTaskParams = new TaskParams();
        localTaskParams.put("action_code", Integer.valueOf(1));
        localTaskParams.put("avatar", this.mCurrentSelectPhoto);
        startToUpdate(localTaskParams);
      }
      this.mImageUri = Uri.fromFile(new File(paramUri.getPath()));
    }
  }

  private void onSubmitBegin(String paramString)
  {
    this.dialog = ProgressDialog.show(this, "", paramString, true);
    this.dialog.setCancelable(true);
  }

  private void onSubmitFailure(String paramString)
  {
    Toast.makeText(this, paramString, 0).show();
    if (this.dialog != null)
      this.dialog.dismiss();
  }

  private void onSubmitFinished()
  {
    if (this.dialog != null)
      this.dialog.dismiss();
    Toast.makeText(this, "操作成功", 0).show();
    switch (this.mTask.getActionCode())
    {
    case 4:
    default:
    case 3:
    case 2:
    case 5:
    case 6:
    }
    while (true)
    {
      while (true)
      {
        while (true)
        {
          while (true)
          {
            return;
            this.mUsernameTextView.setText(this.mTask.getDataResult());
          }
          this.mGenderText.setText(this.mTask.getDataResult());
        }
        this.mSignatrueTextView.setText(this.mTask.getDataResult());
      }
      this.mFlagTextView.setText(this.mTask.getDataResult());
    }
  }

  private void openImageCaptureMenu()
  {
    try
    {
      this.mImageFile = new File(IKnow.mCacheSystem.createImagefileName());
      this.mImageUri = Uri.fromFile(this.mImageFile);
      Intent localIntent = new Intent("android.media.action.IMAGE_CAPTURE");
      localIntent.putExtra("output", this.mImageUri);
      startActivityForResult(localIntent, 7);
      return;
    }
    catch (Exception localException)
    {
      Loger.e("UserInfoActivity", localException.getMessage());
    }
  }

  private void openPhotoLibraryMenu()
  {
    Intent localIntent = new Intent("android.intent.action.GET_CONTENT");
    localIntent.setType("image/*");
    startActivityForResult(localIntent, 8);
  }

  private void showImageSelecte()
  {
    CharSequence[] arrayOfCharSequence = new CharSequence[2];
    arrayOfCharSequence[0] = getString(2131361973);
    arrayOfCharSequence[1] = getString(2131361974);
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
    localBuilder.setTitle(getString(2131361975));
    localBuilder.setItems(arrayOfCharSequence, new DialogInterface.OnClickListener(this)
    {
      public void onClick(, int paramInt)
      {
        switch (paramInt)
        {
        default:
        case 0:
        case 1:
        }
        while (true)
        {
          while (true)
          {
            return;
            UserInfoActivity.access$7(this.this$0);
          }
          UserInfoActivity.access$8(this.this$0);
        }
      }
    });
    localBuilder.create().show();
  }

  private void startToUpdate(TaskParams paramTaskParams)
  {
    if ((this.mTask != null) && (this.mTask.getStatus() == AsyncTask.Status.RUNNING));
    while (true)
    {
      return;
      this.mTask = new UserInfoTask(this, null);
      this.mTask.setListener(this.mTaskListener);
      UserInfoTask localUserInfoTask = this.mTask;
      TaskParams[] arrayOfTaskParams = new TaskParams[1];
      arrayOfTaskParams[0] = paramTaskParams;
      localUserInfoTask.execute(arrayOfTaskParams);
    }
  }

  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    if ((paramInt1 == 7) && (paramInt2 == -1))
      onImageSelected(this.mImageUri);
    while (true)
    {
      do
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                while (true)
                {
                  return;
                  if ((paramInt1 != 8) || (paramInt2 != -1))
                    break;
                  this.mImageUri = paramIntent.getData();
                  if (this.mImageUri == null)
                    this.mImageUri = Uri.parse(paramIntent.getAction());
                  onImageSelected(this.mImageUri);
                }
                if ((paramInt1 != 3) || (paramInt2 != -1))
                  break;
                String str5 = paramIntent.getAction();
                TaskParams localTaskParams5 = new TaskParams();
                localTaskParams5.put("action_code", Integer.valueOf(3));
                localTaskParams5.put("nick", str5);
                startToUpdate(localTaskParams5);
              }
              if ((paramInt1 != 2) || (paramInt2 != -1))
                break;
              String str4 = paramIntent.getAction();
              TaskParams localTaskParams4 = new TaskParams();
              localTaskParams4.put("action_code", Integer.valueOf(2));
              localTaskParams4.put("gender", str4);
              startToUpdate(localTaskParams4);
            }
            if ((paramInt1 != 4) || (paramInt2 != -1))
              break;
            String str3 = paramIntent.getAction();
            if (StringUtil.isEmpty(str3))
              str3 = "111111";
            TaskParams localTaskParams3 = new TaskParams();
            localTaskParams3.put("action_code", Integer.valueOf(4));
            localTaskParams3.put("password", str3);
            startToUpdate(localTaskParams3);
          }
          if ((paramInt1 != 5) || (paramInt2 != -1))
            break;
          String str2 = paramIntent.getAction();
          TaskParams localTaskParams2 = new TaskParams();
          localTaskParams2.put("action_code", Integer.valueOf(5));
          localTaskParams2.put("signature", str2);
          startToUpdate(localTaskParams2);
        }
      while ((paramInt1 != 6) || (paramInt2 != -1));
      String str1 = paramIntent.getAction();
      TaskParams localTaskParams1 = new TaskParams();
      localTaskParams1.put("action_code", Integer.valueOf(6));
      localTaskParams1.put("flag", str1);
      startToUpdate(localTaskParams1);
    }
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    setContentView(2130903094);
    this.mUser = IKnow.mIKnowDataBase.getUser();
    initView();
  }

  protected void onDestroy()
  {
    if (this.mBinded)
    {
      unbindService(this.mSvrConn);
      this.mBinded = false;
    }
    super.onDestroy();
  }

  protected void onPause()
  {
    if (this.mBinded)
    {
      unbindService(this.mSvrConn);
      this.mBinded = false;
    }
    super.onPause();
  }

  protected void onResume()
  {
    super.onResume();
    IKnow localIKnow = (IKnow)getApplication();
    if ((!(this.mBinded)) && (localIKnow.isAccountConfigured()))
      this.mBinded = bindService(SERVICE_INTENT, this.mSvrConn, 1);
  }

  protected void onStart()
  {
    super.onStart();
  }

  private class UserInfoTask extends GenericTask
  {
    private int mActionCode = 0;
    private String mdataResult;
    private String msg = null;

    private UserInfoTask()
    {
      this.mdataResult = null;
    }

    private boolean changeAvatar()
    {
      int i = 0;
      try
      {
        String str = IKnow.mApi.chageAvatar(paramString);
        UserInfoActivity.access$2(this.this$0).createConnection().getIKnowUser().updateUserInfo(str, null, null, null, null);
        IKnow.mIKnowDataBase.updateUserInfo(UserInfoActivity.access$1(this.this$0).getUID(), "image_id", str);
        UserInfoActivity.access$1(this.this$0).setImgeID(str);
        i = 1;
        return i;
      }
      catch (HttpException localHttpException)
      {
        this.msg = "网络超时";
        localHttpException.printStackTrace();
      }
      catch (RemoteException localRemoteException)
      {
        this.msg = localRemoteException.getMessage();
        localRemoteException.printStackTrace();
      }
    }

    private boolean changeFlag()
    {
      int i = 0;
      try
      {
        this.mdataResult = paramString;
        UserInfoActivity.access$2(this.this$0).createConnection().getIKnowUser().updateUserInfo(null, null, paramString, null, null);
        IKnow.mIKnowDataBase.updateUserInfo(UserInfoActivity.access$1(this.this$0).getUID(), "description", paramString);
        UserInfoActivity.access$1(this.this$0).setIntroduction(paramString);
        i = 1;
        return i;
      }
      catch (RemoteException localRemoteException)
      {
        this.msg = localRemoteException.getMessage();
        localRemoteException.printStackTrace();
      }
    }

    private boolean changeGender()
    {
      String str;
      int i = 0;
      this.mdataResult = paramString;
      if (paramString.equalsIgnoreCase("男"))
        str = "1";
      try
      {
        while (true)
        {
          UserInfoActivity.access$2(this.this$0).createConnection().getIKnowUser().updateUserInfo(null, null, null, null, str);
          IKnow.mIKnowDataBase.updateUserInfo(UserInfoActivity.access$1(this.this$0).getUID(), "gender", str);
          UserInfoActivity.access$1(this.this$0).setGender(str);
          i = 1;
          return i;
          if (!(paramString.equalsIgnoreCase("女")))
            break;
          str = "0";
        }
        str = "2";
      }
      catch (RemoteException localRemoteException)
      {
        while (true)
        {
          this.msg = localRemoteException.getMessage();
          localRemoteException.printStackTrace();
        }
      }
    }

    private boolean changeNick()
    {
      int i = 0;
      try
      {
        this.mdataResult = paramString;
        UserInfoActivity.access$2(this.this$0).createConnection().getIKnowUser().updateUserInfo(null, StringUtil.formatStringToXML(paramString), null, null, null);
        IKnow.mIKnowDataBase.updateUserInfo(UserInfoActivity.access$1(this.this$0).getUID(), "nick", StringUtil.formatStringToXML(paramString));
        UserInfoActivity.access$1(this.this$0).setNick(paramString);
        i = 1;
        return i;
      }
      catch (RemoteException localRemoteException)
      {
        this.msg = localRemoteException.getMessage();
        localRemoteException.printStackTrace();
      }
    }

    private boolean changePassword()
    {
      int i = 0;
      try
      {
        UserInfoActivity.access$2(this.this$0).createConnection().getIKnowUser().chagePassword(paramString);
        IKnow.mSystemConfig.setString("account_password", paramString);
        UserInfoActivity.access$1(this.this$0).setPassword(paramString);
        i = 1;
        return i;
      }
      catch (RemoteException localRemoteException)
      {
        this.msg = localRemoteException.getMessage();
        localRemoteException.printStackTrace();
      }
    }

    private boolean changeSignature()
    {
      int i = 0;
      try
      {
        this.mdataResult = paramString;
        UserInfoActivity.access$2(this.this$0).createConnection().getIKnowUser().updateUserInfo(null, null, null, StringUtil.formatStringToXML(paramString), null);
        IKnow.mIKnowDataBase.updateUserInfo(UserInfoActivity.access$1(this.this$0).getUID(), "signature", paramString);
        UserInfoActivity.access$1(this.this$0).setSignature(paramString);
        i = 1;
        return i;
      }
      catch (RemoteException localRemoteException)
      {
        this.msg = localRemoteException.getMessage();
        localRemoteException.printStackTrace();
      }
    }

    protected TaskResult _doInBackground()
    {
      TaskResult localTaskResult;
      TaskParams localTaskParams = paramArrayOfTaskParams[0];
      Object[] arrayOfObject = new Object[1];
      arrayOfObject[0] = Integer.valueOf(2131361874);
      publishProgress(arrayOfObject);
      try
      {
        if ((UserInfoActivity.access$2(this.this$0).createConnection() == null) || (!(UserInfoActivity.access$2(this.this$0).createConnection().isAuthentificated())) || (!(UserInfoActivity.access$2(this.this$0).createConnection().authenticatContentUser())))
        {
          this.msg = "网络超时，修改失败";
          localTaskResult = TaskResult.FAILED;
        }
        else
        {
          this.mActionCode = localTaskParams.getInt("action_code");
          if (this.mActionCode == 1)
            if (changeAvatar(localTaskParams.getString("avatar")))
              localTaskResult = TaskResult.OK;
          else if (this.mActionCode == 3)
            if (changeNick(localTaskParams.getString("nick")))
              localTaskResult = TaskResult.OK;
          else if (this.mActionCode == 4)
            if (changePassword(localTaskParams.getString("password")))
              localTaskResult = TaskResult.OK;
          else if (this.mActionCode == 5)
            if (changeSignature(localTaskParams.getString("signature")))
              localTaskResult = TaskResult.OK;
          else if (this.mActionCode == 2)
            if (changeGender(localTaskParams.getString("gender")))
              localTaskResult = TaskResult.OK;
          else if ((this.mActionCode == 6) && (changeFlag(localTaskParams.getString("flag"))))
            localTaskResult = TaskResult.OK;
        }
      }
      catch (Exception localException)
      {
        this.msg = localException.getMessage();
        localException.printStackTrace();
        localTaskResult = TaskResult.FAILED;
      }
      return localTaskResult;
    }

    public int getActionCode()
    {
      return this.mActionCode;
    }

    public String getDataResult()
    {
      return this.mdataResult;
    }

    public String getMsg()
    {
      return this.msg;
    }
  }

  private class XmppServiceConnection
  implements ServiceConnection
  {
    public void onServiceConnected(, IBinder paramIBinder)
    {
      UserInfoActivity.access$6(this.this$0, IXmppFacade.Stub.asInterface(paramIBinder));
    }

    public void onServiceDisconnected()
    {
      UserInfoActivity.access$6(this.this$0, null);
    }
  }
}